package com.bsoft.hospitalchs.api;

import com.bsoft.hospitalchs.common.MyApplication;
import com.bsoft.hospitalchs.utils.LogUtil;

import java.util.List;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

public class SimpleCookieJar implements CookieJar {

    public PersistentCookieStore cookieStore = new PersistentCookieStore(MyApplication.getInstance());

    public  PersistentCookieStore getCookieStore() {
        return cookieStore;
    }

    public synchronized void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
        if (cookies != null && cookies.size() > 0) {
            for (Cookie item : cookies) {
                cookieStore.add(url, item);
            }
        }
    }


    @Override
    public synchronized List<okhttp3.Cookie> loadForRequest(HttpUrl url) {
        List<Cookie> cookies = cookieStore.get(url);
        LogUtil.e("API", url);
        return cookies;
    }
}
